<?php

namespace backend\modules\business\methods\base;
error_reporting(0);
class HandleBase {
	/**
	 * 调用方法配置项
	 * @var unknown
	 */
	private $config;
	/**
	 * 实例化类的实例
	 * @var unknown
	 */
	private $Object;
	/**
	 * get参数
	 * @var unknown
	 */
	private $getparam;
	/**
	 * post参数
	 * @var unknown
	 */
	private $postparam;
	/**
	 * 初始化
	 * @date: 2016-3-4 
	 * @author: futao
	 */
	public function init($object)
	{
		$this->Object = $object;
		$this->getparam = \Yii::$app->request->get();
		$this->postparam = \Yii::$app->request->post();
		$this->config = include(__DIR__.'/../config/config.php');
	}
	/**
	 * 根据参数调用方法(区分大小写)
	 * @date: 2016-2-25
	 * @author: futao
	 */
	public function run()
	{
		$actionArr = $this->config[$this->getParam('action','index')];
		if($actionArr==''){
			throw new \Exception('参数错误！');
		}
		if($actionArr['namespace']==''){
			throw new \Exception('配置错误！');
		}
		if($actionArr['method']==''){
			$actionArr['method']='index';
		}
		$method = $actionArr['method'];
		$namespace = $actionArr['namespace'];
		$Result = new $namespace($this->Object,$method,$this->getparam,$this->postparam,$actionArr);
		return $Result->$method();
	}
	/**
	 * 返回get参数值
	 * @date: 2016-2-25
	 * @author: futao
	 */
	public function getParam($key,$default='')
	{
		return $this->getparam[$key] ? $this->getparam[$key] : $default;
	}
	/**
	 * 返回post参数值
	 * @date: 2016-2-25
	 * @author: futao
	 */
	public function postParam($key,$default=''){
		return $this->postparam ? $this->postparam[$key] : $default;
	}
}

?>